Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GPU: Add integer color target clears #11347

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

rabbit-ecl
Copy link
Contributor

@rabbit-ecl rabbit-ecl commented Oct 27, 2024

Adds proper clearing of integer color formats using a Vulkan-like SDL_GPUClearColor union in place of SDL_FColor.
D3D backends will still need a shader path to support the full range of R32_UINT / R32_INT formats.
Also added 32-bit integer formats missing from some SDL_sysgpu.h helper functions.

Existing Issue(s)

#11343

@icculus
Copy link
Collaborator

icculus commented Oct 27, 2024

This is a dumb question, but do we need this? Is there a reason an app can't just convert 4 ints to floats before clearing?

@TheSpydog
Copy link
Collaborator

Is there a reason an app can't just convert 4 ints to floats before clearing?

This would work for Metal and Vulkan (with some bitcasting to preserve the integer bit pattern), but not for D3D. The reason is that you can have integer texture formats with more bits than can be precisely represented by a float.

E.g. if you have an R32_INT texture and you want to clear it to a value of 2^24 or above, you're out of luck. D3D will choose the closest integer value that it can represent as a float, which caps your maximum clear value. The only way to work around this is by clearing the target with a shader, which is what D3D's docs recommend.

Though, as the OP notes, this PR does not include the D3D shaders for clearing. @rabbit-ecl Could you write those up and provide a test program with integer texture clears in action? You can PR the test case to the SDL_gpu_examples repo.

@icculus
Copy link
Collaborator

icculus commented Oct 27, 2024

I'm still skeptical this is worth adding for high-precision clearing, but if y'all think it's worth it I won't stand in the way.

@thatcosmonaut
Copy link
Collaborator

I'm also presently of the opinion that this is not really worth it.

@rabbit-ecl
Copy link
Contributor Author

@rabbit-ecl Could you write those up and provide a test program with integer texture clears in action? You can PR the test case to the SDL_gpu_examples repo.

Yeah I'll look into it and we can always drop it if it ends up being too hacky. I think most of the hard work here has already been done for the blit emulation paths.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants